use std::sync::mpsc::Sender;

use crate::panel::{AttrPanelMessage, LayerPanelMessage, UiPanelMessage};

#[derive(Debug)]
pub struct EditorMessageCenter {
    layer_panel_sender: Option<Sender<LayerPanelMessage>>,
    attr_panel_sender: Option<Sender<AttrPanelMessage>>,
    ui_panel_sender: Option<Sender<UiPanelMessage>>,
}

impl EditorMessageCenter {
    pub fn new() -> Self {
        Self {
            layer_panel_sender: None,
            attr_panel_sender: None,
            ui_panel_sender: None,
        }
    }

    pub fn set_layer_panel_sender(&mut self, sender: Sender<LayerPanelMessage>) {
        self.layer_panel_sender = Some(sender);
    }

    pub fn send_to_layer_panel(&self, msg: LayerPanelMessage) {
        if let Some(sender) = &self.layer_panel_sender {
            sender.send(msg).unwrap();
        }
    }

    pub fn set_attr_panel_sender(&mut self, sender: Sender<AttrPanelMessage>) {
        self.attr_panel_sender = Some(sender);
    }

    pub fn send_to_attr_panel(&self, msg: AttrPanelMessage) {
        if let Some(sender) = &self.attr_panel_sender {
            sender.send(msg).unwrap();
        }
    }

    pub fn set_ui_panel_sender(&mut self, sender: Sender<UiPanelMessage>) {
        self.ui_panel_sender = Some(sender);
    }

    pub fn send_to_ui_panel(&self, msg: UiPanelMessage) {
        if let Some(sender) = &self.ui_panel_sender {
            sender.send(msg).unwrap();
        }
    }
}
